/*
@Copyright:LintCode
@Author:   tjyemail
@Problem:  http://www.lintcode.com/problem/best-time-to-buy-and-sell-stock
@Language: C++
@Datetime: 16-02-09 05:43
*/

class Solution {
public:
    /**
     * @param prices: Given an integer array
     * @return: Maximum profit
     */
    int maxProfit(vector<int> &prices) {
        // write your code here
        if (prices.size()<2)
            return 0;
        int min = 1<<30;
        int profit=0;
        for(int i=0;i<prices.size();++i){
            min = (min<prices[i]?min:prices[i]);
            profit = (profit>prices[i]-min?profit:prices[i]-min);
        }
        return profit;
    }
};
